using UnityEngine;
using System.Collections;

public class LifeCondition : MonoBehaviour {
	
	public int maxTimeToLive;
	public Light localLight;
	
	private int timeToLive;
	
	void Start(){
		timeToLive = maxTimeToLive;
	}
	
	void Update () {
		//Liga o lampiao
		if(!localLight.enabled && Input.GetButton("LightOn")){
			localLight.enabled = true;
		}
		
		if(RenderSettings.ambientLight.r < 0.1){
			if(!localLight.enabled){
				if(timeToLive > 0){
					//Perde vida
					--timeToLive;
					print("Diminuindo: " + timeToLive);
				}
				else {
					//Morreu
					print("Morreu de susto!");
				}
			}
		}
		else{
			if(timeToLive < maxTimeToLive){
				//Recuperando a vida
				++timeToLive;
				print("Recuperando vida: " + timeToLive);
			}
		}
	}
}